<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page isELIgnored="false" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'tianjia.jsp' starting page</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<link rel="stylesheet" type="text/css" href="bootstrap-3.3.7/css/bootstrap.css">
    <script type="text/javascript" src="bootstrap-3.3.7/js/jquery-3.3.1.min.js"></script>
	<script type="text/javascript" src="bootstrap-3.3.7/js/bootstrap.min.js"></script>
	<script type="text/javascript">
	
		$(function(){
			$.post(
				"selecthobby",
				{},
				function(obj){
					for(var i=0; i<obj.length; i++){
							$("[name='spp']").append("<input type='checkbox' name='ck' value="+obj[i].hname+">"+obj[i].hname);
					}
				},
				"json"
			);
			$.post(
				"selectectur",
				{},
				function(obj){
					for(var i=0; i<obj.length; i++){
							$("[name='asp']").append("<input type='checkbox' name='ack' value="+obj[i].ename+">"+obj[i].ename);
					}
				},
				"json"
			);
			
			$.post(
				"selectrang",
				{},
				function(obj){
					for(var i=0; i<obj.length; i++){
							$("[name='bsp']").append("<input type='checkbox' name='bck' value="+obj[i].rname+">"+obj[i].rname);
					}
				},
				"json"
			);
		})
		
		
		$(function(){  
        	$('li:has(ul)').addClass('parent_li').find(' > input').attr('title', 'Collapse this branch'); 
        	$('li.parent_li > input').on('click', function (e) {
            	var children = $(this).parent('li.parent_li').find(' > ul > li');  
            	if (children.is(":visible")) {  
               		children.hide('fast');  
                	$(this).attr('title', 'Expand this branch').addClass('icon-plus-sign').removeClass('icon-minus-sign');  
            	} else {  
                	children.show('fast'); 
                	$(this).attr('title', 'Collapse this branch').addClass('icon-minus-sign').removeClass('icon-plus-sign');  
            	}   
            	e.stopPropagation();  
        });  
    }); 
    
    
    function tijiao(){
    	var sname = $("[name='sname']").val();
    	var sex = $("[name='sex']").val();
    	var age = $("[name='age']").val();
    	var hobby = $("[name='ck']:checked").map(function(){
    		return this.value;
    	}).get().join();
    	var ectur = $("[name='ack']:checked").map(function(){
    		return this.value;
    	}).get().join();
    	var rang = $("[name='bck']:checked").map(function(){
    		return this.value;
    	}).get().join();
    		$.post(
    			"addstudent",
    			{
    				"sname":sname,
    				"sex":sex,
    				"age":age,
    				"hobby":hobby,
    				"ectur":ectur,
    				"rang":rang
    			},
    			function(obj){
    				if(obj){
    					alert("添加成功！");
    					location = "getlist";
    				}
    			},
    			"json"
    		);
    }
    
	</script>

  </head>
  
  <body>
    <p style="font-size: 30px;text-align: center;">添加页面</p>
    	<input name="sid" value="${sid}" type="hidden"><br>
    	姓名：<input name="sname" value="${stu.sname}"><br>
  	            性别：<input name="sex" value="${stu.sex}"><br>
  	            年龄：<input name="age" value="${stu.age}"><br>
        <ul>  
            <li>
            	<input type="checkbox"> 爱好
                <ul>    
                	<li>
                        <span name="spp"></span>
                    </li> 
                </ul>  
             </li>
             <li>
            	<input type="checkbox"> 部门
                <ul>    
                	<li>
                        <span name="asp"></span>
                    </li> 
                </ul>  
             </li>
             <li>
            	<input type="checkbox"> 职位
                <ul>    
                	<li>
                        <span name="bsp"></span>
                    </li> 
                </ul>  
             </li>
         </ul>
    	<button class="btn btn-primary" onclick="tijiao()">提交</button> 
  </body>
</html>
